package com.fanco.learn_datastruct_leetcode.juc;

import java.util.concurrent.*;

/**
 * @author qiaowang 2021/8/23
 * 描述
 */
public class ThreadPoolExecutorDemo {
    public static void main(String[] args) {

        ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(
                        10,
                        20,
                        5L,
                        TimeUnit.SECONDS,
                        new ArrayBlockingQueue<>(3),
                        Executors.defaultThreadFactory(),
                        new ThreadPoolExecutor.DiscardOldestPolicy());

        for (int i = 0; i < 30; i++) {
            int finalI = i;
            threadPoolExecutor.execute(() -> {
                System.out.println("当前线程执行," + finalI);
                try {
                    TimeUnit.SECONDS.sleep(5);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }

        threadPoolExecutor.shutdown();
    }
}
